<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="admin/_fragment :: head">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>AdminLTE 3 | Log in</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Font Awesome -->
    <link rel="stylesheet" href="./plugins/fontawesome-free/css/all.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="./css/adminlte.min.css">
    <!-- Google Font: Source Sans Pro -->
    <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
</head>
<body class="hold-transition login-page">
<div class="login-box">
    <div class="login-logo">
        <b>博客后端管理系统</b>
    </div>
    <!-- /.login-logo -->
    <div class="card">
        <div class="card-body login-card-body">
            <form action="dashboard.html" method="post">
                <div class="input-group mb-3">
                    <input type="text" name="username" id="username" class="form-control" placeholder="用户名">
                    <div class="input-group-append">
                        <div class="input-group-text">
                            <span class="fas fa-envelope"></span>
                        </div>
                    </div>
                </div>
                <div class="input-group mb-3">
                    <input type="password" class="form-control" id="password" name="password" placeholder="Password">
                    <div class="input-group-append">
                        <div class="input-group-text">
                            <span class="fas fa-lock"></span>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <!-- /.col -->
                    <button type="button" onclick="login()" class="btn btn-success btn-block">登录</button>
                    <!-- /.col -->
                </div>
            </form>

            <div class="social-auth-links text-center mb-3">
                <p id="span01" style="color: red" th:text="${error}">- OR -</p>
                <a href="#" class="btn btn-block btn-primary">
                    <i class="fab fa-github mr-2"></i> Sign in using Github
                </a>
            </div>
            <!-- /.social-auth-links -->
        </div>
        <!-- /.login-card-body -->
    </div>
</div>
<!-- /.login-box -->

<div th:replace="admin/_fragment :: js">
    <!-- jQuery -->
    <script src="./plugins/jquery/jquery.min.js"></script>
    <!-- Bootstrap 4 -->
    <script src="./plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
    <!-- AdminLTE App -->
    <script src="./js/adminlte.min.js"></script>
</div>
<script type="text/javascript">
    function login() {
        // alert(111)
        var username = document.getElementById('username').value;
        var password = document.getElementById('password').value;
        // alert(username)
        if (username == '' && password == '') {
            document.getElementById('span01').innerHTML = '账号和密码不能为空'

        } else if (username == '') {
            document.getElementById('span01').innerHTML = '账号不能为空'

        } else if (password == '') {
            document.getElementById('span01').innerHTML = '密码不能为空'

        } else {
            // alert(11)
            $.ajax({
                url: '/admin/login',
                type: 'get',
                data: {'username': username, 'password': password},
                success: function (data) {
                    if (data == 'success') {
                        // alert(data)
                        location.href = '/admin/toindex'
                    } else {
                        // alert(data)
                        document.getElementById('span01').innerHTML = '账号或密码错误'
                    }
                }
            })
        }
        // var span01 = ;

    }
</script>
</body>
</html>